package com.atguigu.guli.service.edu.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Video;
import com.atguigu.guli.service.edu.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2020-10-14
 */
@RestController

@RequestMapping("/admin/edu/video")
@Api(tags = "课时管理")
public class AdminVideoController {
    @Autowired(required = true)
    private VideoService videoService;


    @ApiOperation("新增课时")
    @PostMapping("/save")
    public R saveVideo(@RequestBody Video video){
        boolean save = videoService.save(video);
        if (save){
            return R.ok().message("新增成功");
        }else {
            return R.error().message("新增失败");
        }
    }


    @ApiOperation("删除课时")
    @DeleteMapping("/remove/{id}")
    public R removeVideo(@PathVariable String id){
        videoService.removeMediaById(id);
        boolean b = videoService.removeById(id);
        if (b) {
            return R.ok().message("删除成功");
        }else {
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("修改章节")
    @PutMapping("/update")
    public R updateVideo(@RequestBody Video video){
        boolean b = videoService.updateById(video);
        if (b){
            return R.ok().message("修改成功");
        }else{
            return R.error().message("无此数据");
        }
    }


    @ApiOperation("查询课时")
    @GetMapping("/get/{id}")
    public R getVideo(@PathVariable String id){
        Video video = videoService.getById(id);
        if (video != null){
            return R.ok().data("item",video);
        }else {
            return R.error().message("无此数据");
        }
    }
}

